//
//  ColumnCollectionReusableView.m
//  14-HomeWork-礼物说
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ColumnCollectionReusableView.h"
#import "ColumnCollectionViewCell.h"
#define kCollectionViewCellColumn @"reuseOfColumn"

@interface ColumnCollectionReusableView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation ColumnCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIButton *findButton = [UIButton buttonWithType:UIButtonTypeSystem];
        findButton.frame = CGRectMake(10, 0, frame.size.width - 20, 40);
        [findButton setTitle:@" 快选一份七夕礼物, 送给心爱的Ta吧" forState:UIControlStateNormal];
        findButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        findButton.titleLabel.font = [UIFont systemFontOfSize:18];
        findButton.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
        [findButton setTintColor:[UIColor colorWithWhite:0.702 alpha:0.728]];
        [findButton setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 50, 30)];
        label.text = @"栏目";
        label.font = [UIFont systemFontOfSize:18];
        label.textColor = [UIColor colorWithWhite:0.702 alpha:0.728];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(CGRectGetWidth(frame) / 2 + 100, 40, 100, 30);
        [button setTitle:@"查看全部 >" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:18];
        [button setTintColor:[UIColor colorWithWhite:0.400 alpha:1.000]];
        [self addSubview:findButton];
        [self addSubview:label];
        [self addSubview:button];
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(CGRectGetWidth(frame) * 5 / 6, (CGRectGetHeight(frame) * 2 / 9 + 15));
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 70, frame.size.width, frame.size.width - 5) collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[ColumnCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewCellColumn];
        _collectionView.backgroundColor = [UIColor whiteColor];

        [self addSubview:_collectionView];
        
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ColumnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellColumn forIndexPath:indexPath];
    return cell;
}

@end
